/**
 * @author kevinlaizhiyu@foxmail.com
 * @description user model
 * @date 2024-6-4
 * @version 1.0.0
 */
import mongoose, {Schema} from "mongoose";

const {ObjectId} = mongoose.Types;

export const enum Gender {
    MALE = 1, // 男
    FEMALE = 2, // 女
}

export const enum SPORT_LEVEL_ENUM {
    BEGINNER = 10, // 初级
    INTERMEDIATE = 20, // 中级
    ADVANCED = 30, // 高级
    PROFESSIONAL = 40, // 专家
}

export interface IUser {
    userId: string;
    userName: string;
    password?: string;
    tel?: string;
    email?: string;
    avatar?: string | undefined;
    gender?: Gender;
    age: number;
    activityType?: string;
    sportsCategory?: string;
    sportsLevel?: SPORT_LEVEL_ENUM;
    nickname?: string;
    wechatId?: string;
    createdAt: number;
    updatedAt: number;
}

const userSchema = new Schema({
    userId: {
        type: String,
        default: () => new ObjectId(),
        index: true,
        unique: true,
    }, // 用户ID
    userName: {type: String, required: true}, // 用户名称
    password: {type: String, required: false}, // 密码
    tel: {type: String}, // 手机号
    email: {type: String}, // 邮箱
    avatar: {type: String}, // 头像
    gender: {type: Number, enum: [Gender.MALE, Gender.FEMALE], default: Gender.MALE},
    age: {type: Number, default: 0},
    activityType: {type: String},
    sportsCategory: {type: String, default: ''},
    sportsLevel: {
        type: Number,
        enum: [SPORT_LEVEL_ENUM.BEGINNER, SPORT_LEVEL_ENUM.INTERMEDIATE, SPORT_LEVEL_ENUM.ADVANCED, SPORT_LEVEL_ENUM.PROFESSIONAL],
        default: SPORT_LEVEL_ENUM.BEGINNER
    },
    nickname: {type: String},
    wechatId: {type: String},
    createdAt: {type: Number, default: Date.now}, // 创建时间
    updatedAt: {type: Number, default: Date.now}, // 更新时间
});

const UserModel = mongoose.model("users", userSchema);

export default UserModel;
